package com.cskaoyan.config3;

import com.alibaba.druid.pool.DruidDataSource;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * @author stone
 * @date 2022/09/05 14:47
 */
@Configuration
@Data //提供set方法
@ConfigurationProperties(prefix = "cskaoyan.datasource")//前缀+成员变量名
public class DatasourceConfiguration3 {

    // 这些成员变量的值，我们期望从配置文件中获得
    String driverClass; 
    String url; 
    String username; 
    String password; 

    @Bean
    public DataSource dataSource3() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driverClass);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;
    }
}
